package com.gl.rent;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.convert.Convert;
import com.gl.common.util.SecurityUtils;
import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.HouseRecommendation;
import com.haixiaoke.saas.repository.service.IHouseRecommendationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公寓推荐设置Controller
 * 
 * @author haixiaoke
 * @date 2023-04-11
 */
@RestController
@RequestMapping("/base/recommendation")
public class HouseRecommendationController extends BaseController {
    @Autowired
    private IHouseRecommendationService houseRecommendationService;

    /**
     * 查询公寓推荐设置列表
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:recommendation:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseRecommendation houseRecommendation) {
        startPage();
        List<HouseRecommendation> list = houseRecommendationService.selectHouseRecommendationList(houseRecommendation);
        return getDataTable(list);
    }

    /**
     * 获取公寓推荐设置详细信息
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:recommendation:query')")
    @GetMapping(value = "/{recommendationId}")
    public AjaxResult getInfo(@PathVariable("recommendationId") Long recommendationId) {
        return success(houseRecommendationService.selectHouseRecommendationByRecommendationId(recommendationId));
    }

    /**
     * 新增公寓推荐设置
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:recommendation:add')")
//    @Log(title = "公寓推荐设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseRecommendation houseRecommendation) {
        String id = Convert.toStr(SecurityUtils.getLoginUserId());
        houseRecommendation.setCreateBy(id);
        return toAjax(houseRecommendationService.insertHouseRecommendation(houseRecommendation));
    }

    /**
     * 修改公寓推荐设置
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:recommendation:edit')")
//    @Log(title = "公寓推荐设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseRecommendation houseRecommendation) {
        String id = Convert.toStr(SecurityUtils.getLoginUserId());
        houseRecommendation.setUpdateBy(id);
        return toAjax(houseRecommendationService.updateHouseRecommendation(houseRecommendation));
    }

    /**
     * 删除公寓推荐设置
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:recommendation:remove')")
//    @Log(title = "公寓推荐设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recommendationIds}")
    public AjaxResult remove(@PathVariable Long[] recommendationIds) {
        return toAjax(houseRecommendationService.deleteHouseRecommendationByRecommendationIds(recommendationIds));
    }

    /**
     * 修改房屋推荐的状态
     * @param houseRecommendation
     * @return
     */
    @PutMapping("updateState")
    public AjaxResult updateState(@RequestBody HouseRecommendation houseRecommendation) {
        String id = Convert.toStr(SecurityUtils.getLoginUserId());
        houseRecommendation.setUpdateBy(id);
        return toAjax(houseRecommendationService.updateState(houseRecommendation));
    }

}
